package com.example.sxwwebplugin;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;

/**
 * SxwWebPlugin
 */
public class SxwWebPlugin implements MethodCallHandler {
    private Registrar registrar;

    private SxwWebPlugin(Registrar registrar) {
        this.registrar = registrar;
    }

    /**
     * Plugin registration.
     */
    public static void registerWith(Registrar registrar) {
        final MethodChannel channel = new MethodChannel(registrar.messenger(), "com.sxw365.sxw_web_plugin");
        channel.setMethodCallHandler(new SxwWebPlugin(registrar));
    }

    @Override
    public void onMethodCall(MethodCall call, Result result) {
        if (call.method.equals("open")) {
            String url = call.arguments();
            WebActivity.startUrl(registrar.activity(), url);
            result.success(1);
        } else {
            result.notImplemented();
        }
    }
}
